home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / chrono.z / chrono
Encoding:
Text File  |  1997-01-22  |  2.1 KB  |  79 lines

  1. #
  2. # Chronological sort, grouping by message thread
  3. #
  4. function chrono() {
  5.     #
  6.     # If we are first entering, initialize the beginning and end
  7.     # of the range to sort.  If an argument was given, use that
  8.     # as the place to begin the sort.
  9.     # Also create a few useful command shorthands for later.
  10.     #
  11.     if ! $?begin
  12.     unmark *
  13.     if $?1
  14.         set begin = "$1"
  15.     else
  16.         set begin = 1
  17.     endif
  18.     msg_list $ | set end
  19.     cmd next_number 'msg_list +'
  20.     cmd first_number 'msg_list - ; msg_list .'
  21.     cmd last_number 'msg_list + ; msg_list .'
  22.     endif
  23.     #
  24.     # Now sort all the messages from the beginning point
  25.     # through the end, by date ....
  26.     #
  27.     $begin - $ | sort -d | msg_list -
  28.     #
  29.     # Find the messages with the same subject as the current message.
  30.     # If the current message has no subject, find all messages that
  31.     # reference the message ID of the current message.
  32.     # Mark any messages that match.
  33.     #
  34.     if $?[%s]
  35.     eval -h pick -r $begin - $ -s %s$ | mark
  36.     else
  37.     eval -h pick -r $begin - $ -h references %i | mark
  38.     endif
  39.     #
  40.     # Sort by priority to move the marked messages to the top.
  41.     #
  42.     $begin - $ | sort -p
  43.     #
  44.     # Find the range boundaries of the set of marked messages,
  45.     # then unmark them.
  46.     #
  47.     :m | first_number | set first
  48.     :m | last_number | set last
  49.     unmark *
  50.     #
  51.     # If there is a range of more than one message,
  52.     # re-sort that range by date, and unset the vars.
  53.     #
  54.     if $first != $last
  55.     $first - $last | sort -d | next_number
  56.     endif
  57.     unset first last
  58.     #
  59.     # Advance the beginning point to the next message beyond those sorted.
  60.     #
  61.     next_number | set begin
  62.     #
  63.     # If we've reached the end of the list, clean up and return
  64.     #
  65.     if $begin == $end
  66.     unset begin end recursive
  67.     uncmd next_number first_number last_number
  68.     return 0
  69.     endif
  70.     #
  71.     # If we have more messages to sort, repeat.  This will abort
  72.     # without completing if there are more than 100 distinct subjects,
  73.     # because stack depth is limited.  The user can repeat the "chrono"
  74.     # command to continue sorting, because "begin" will still be set.
  75.     #
  76.     set recursive
  77.     chrono
  78. }
  79.